package lt.hsu.login.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import lt.hsu.login.entities.UserEntity;
import lt.hsu.login.req.LoginInfo;
import lt.hsu.login.service.IUserService;
import lt.hsu.login.vo.ResLogin;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Validated
@Slf4j
@Tag(name = "Login", description = "登录接口")
public class LoginController {

    @Resource
    private IUserService userService;

    @Operation(summary = "登录",description = "账号密码登录")
    @PostMapping(path = "/login",consumes = "application/json")
    public ResLogin login(@RequestBody @Valid LoginInfo loginInfo) {
        UserEntity entity = new UserEntity();
        entity.setUsername("admin");
        entity.setPassword("admin");
        entity.setRole("EDITOR");
        userService.saveOrUpdate(entity);
        // 登录逻辑
        return new ResLogin();
    }

    @Operation(summary = "查询用户",description = "查询用户")
    @PostMapping(path = "/findUser",consumes = "application/json")
    public UserEntity findUser() {
        QueryWrapper<UserEntity> eq = new QueryWrapper<>();
        eq.eq("username", "admin");
        return userService.getOne(eq);
    }

}
